<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width='device-width', initial-scale=1.0" />
    <script src="https://cdn.jsdelivr.net/npm/vue@2.7.8"></script>
    <title>vue4事件绑定</title>
  </head>
  <body>
    <div id="app">
      <p>count的值是:{{ count }}</p>
      <!-- 绑定事件的时候可以传参 -->
      <!-- v-on:这个指令可以简写@ -->
      <button @click="add(1)">+1</button>
      <button @click="sub">-1</button>
    </div>
    <script>
      const vm = new Vue({
        el: "#app",
        data: {
          count: 0,
        },
        //methods作用是定义事件处理函数
        methods: {
          add(n) {
            this.count += n; //vm.count同样可以实现！！！！vm ==  this
          },
          sub() {
            this.count -= 1;
          },
        },
      });
    </script>
  </body>
</html>
